<?php

namespace app\api\controller;

use app\common\business\User as userBn;
use app\common\business\Match as matchBn;
use app\common\business\Guess as guessBn;
use think\Validate;

class Match extends \app\common\controller\HomeBase {

    /**
     * 今日答题，明日答题
     */
    public function matchlist() {
        try {
            $params = input(); 
             $params['status']=1;
             $user_id=$this->_isLogin();
            $data = matchBn::matchlist($params,$user_id);
            $this->_echoSuccessMessage('', $data);
        } catch (\Exception $e) {
            $this->_echoErrorMessage($e->getMessage(), $e->getCode());
        }
    }

    /**
     * 今日答题，明日答题
     */
    public function askshow() {
        try {
            $user_id = $this->_validLogin();
            $params = input();
            $data = matchBn::askshow($params);
            $this->_echoSuccessMessage('', $data);
        } catch (\Exception $e) {
            $this->_echoErrorMessage($e->getMessage(), $e->getCode());
        }
    }

    /**
     * 提交答题
     * match_id
     * answer[]
     * ask_id,answer_content
     */
    public function addanswer() {
        try {
            $user_id = $this->_validLogin();
            $params = input();
            /* $params['answer'] = array(
              array('ask_id' => 1, 'answer_content' => 1),
              array('ask_id' => 2, 'answer_content' => 0),
              array('ask_id' => 3, 'answer_content' => 1),
              ); */
            $params['user_id'] = $user_id; 
            $data = matchBn::addanswer($params);
            
            $this->_echoSuccessMessage('', $data);
        } catch (\Exception $e) {
            $this->_echoErrorMessage($e->getMessage(), $e->getCode());
        }
    }

    /**
     * 添加推演
     * guess_16='法国;中国;dsfdf'
     * guess_8='dsfsdf;sdfsdfs'
     * guess_4='dsfsdf;dsfsdf'
     * guess_1='sdfsd;sdfsd'
     * guess_3='sdfsd;sdfsd'
     * guess_first='sdfsd'
     * guess_three="ddd"
     * 
     */
    public function add() {
        try {
            $user_id = $this->_validLogin();
            $params = input();
            $validate = Validate('Guess');
            $params = $validate->scene('add')->check($params);
            if (!$params) {
                exception($validate->getError(), 10000003);
            }
            $params['guess_type'] = 32;
            $params['user_id'] = $user_id;
            $data = guessBn::addguess($params);
            $this->_echoSuccessMessage('推演冠军成功', $data);
        } catch (\Exception $e) {
            $this->_echoErrorMessage($e->getMessage(), $e->getCode());
        }
    }

    /**
     * 积分排行榜
     */
    public function pointlist() {
        try {
            $user_id = $this->_isLogin();
            $params = input();
            $validate = Validate('Guess');
            $params = $validate->scene('pointlist')->check($params);
            if ($validate->getError()) {
                exception($validate->getError(), 10000003);
            }
            $params["need_total"] = 1;
            $data = userBn::pointlist($params, $user_id);
            $this->_echoSuccessMessage('', $data);
        } catch (\Exception $e) {
            $this->_echoErrorMessage($e->getMessage(), $e->getCode());
        }
    }

    /**
     * 积分排行榜
     */
    public function firstlist() {
        try {
            $user_id = $this->_isLogin();
            $params = input();
            $validate = Validate('Guess');
            $params = $validate->scene('pointlist')->check($params);
            if ($validate->getError()) {
                exception($validate->getError(), 10000003);
            }
            $params["need_total"] = 1;
            $data = guessBn::firstlist($params, $user_id);
            $this->_echoSuccessMessage('', $data);
        } catch (\Exception $e) {
            $this->_echoErrorMessage($e->getMessage(), $e->getCode());
        }
    }
    
    /**
     * 赛程表
     */
    public function sjbsclist() {
        try {
            $params = input();
            $params['count']=99;
            $data = matchBn::sjbsclist($params);
            $this->_echoSuccessMessage('', $data);
        } catch (\Exception $e) {
            $this->_echoErrorMessage($e->getMessage(), $e->getCode());
        }
    }
    

}
